package com.stormragetech.sylwanas.util;

import com.stormragetech.sylwanas.common.ConfInfo;
import com.stormragetech.sylwanas.common.RabbitInfo;
import lombok.extern.log4j.Log4j2;
import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

/**
 * description: //TODO
 *
 * @author: Xue Bin
 * @version: 1.0.0-SNAPSHOT
 */
@Log4j2
public class YamlConv {

    public RabbitInfo conv(String fileName) {

        String path = getClass().getClassLoader().getResource(fileName).getPath();
        log.debug("path is: {}", path);
        if (null == path || path.length() <= 0) {
            return null;
        }

        Yaml yaml = new Yaml();
        try {
            log.info("[ YAML ] - {}", yaml.loadAs(new FileInputStream(new File(path)), ConfInfo.class).getRabbit());
            return yaml.loadAs(new FileInputStream(new File(path)), ConfInfo.class).getRabbit();
        } catch (FileNotFoundException e) {
            log.error("exception is: {}", e);
            return null;
        }
    }

}
